/**
 * RETURN-11
 * 2018-01-11
 * data : {"RETURN":"-11","MSG":"请选择房型","radiobutton":"rb_rmtype","rb_rmtype":[{"name":"AAAA","value":"1"},{"name":"FMC","value":"家庭(儿童)房"},{"name":"FMY","value":"家庭(青少年)房"},{"name":"gdhj","value":"789"},{"name":"HLW","value":"好莱坞房"},{"name":"PF  ","value":"城市帐假房"},{"name":"PM  ","value":"团队主帐房"},{"name":"PYST","value":"1234"},{"name":"PYTF","value":"4561"},{"name":"SK","value":"大床房"},{"name":"SKK","value":"CES"},{"name":"ST","value":"双人间"},{"name":"STT","value":"豪华大床"}]}
 */
;(function ($) {
	//入口
	$.fn.RETURN_11=function(options){
    	//创建对象
		var $ele = new returnModal(this, options);
		//入口
		$ele.initModal();
	}
	
	//构造函数
    var returnModal = function(ele, opt) {   	
    	//选择器对象    	
        this.$element=ele;   
        //默认参数
        this.defaults = {
        	data:function(){},//return数据
    		dataBack:function(){},//完成结账回调函数
    		returnBack:function(){},//返回回调函数
        },        
        //初始化参数
        this.options = $.extend({}, this.defaults, opt);
    }
    
    //属性方法
    returnModal.prototype = {
    	//临时变量
		defaultValue:null,
    	defaultPayment:null,
    	//获取默认值
    	initModal:function(){
    		var $t=this;
    		var $opt=$t.options;
    		
    		$t.modalHtml();
		},
		//初始化模态窗体
    	modalHtml:function(){
    		var $t=this;
    		var $opt=$t.options;
//    		alert(JSON.stringify($t.defaultValue));
    		
    		$t.$element.addClass("modal").attr("tabindex","-1").attr("data-backdrop","static");
    		var html =	'<div class="modal-dialog" style="min-width: 600px;">'+
							'<div class="modal-content">'+
							'<div class="modal-body">'+
    							'<button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>'+
    							'<div class="bootbox-body">'+
	    							'<h3 class="header smaller lighter blue"><i class="ace-icon fa fa-bullhorn"></i>'+$opt.data.MSG+'</h3>'+
	    							'<div id="radioDiv" class="no-margin no-padding alert alert-block" style="line-height:2">'+
									'</div>'+
								'</div>'+
    						'</div>'+
							'<div class="modal-footer">'+
								'<div align="right" width="50%" style="display:inline">'+
									'<div class="btn-group">'+
										'<button id="btnDataBack" type="button" class="btn btn-sm btn-info" >'+
											'<i class="ace-icon fa fa-check"></i>'+
											$.i18n.propJsp("确定")+
										'</button>'+
									'</div>'+
									'<div class="btn-group">'+
										'<button id="" type="button" class="btn btn-sm btn-default" data-dismiss="modal">'+
											'<i class="ace-icon fa fa-undo"></i>'+
											$.i18n.propJsp("关闭")+
										'</button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>';
    		$t.$element.html(html);
    		//初始化结账方式
    		$t.init();
    	},
    	//初始化结账方式
    	init:function(){
    		var $t=this;
    		var $opt=$t.options;
    		var el=$t.$element;
    		//模态成功加载完成调用
    		$t.show();
    		
    		//添加选项
    		$t.addRadioBtn();
    		
    		//绑定事件
    		$t.bindEvent();
    		
    	},
    	//添加选项
		addRadioBtn:function(){
			var $t=this;
    		var $opt=$t.options;
    		var el=$t.$element;
    		
    		$.each($opt.data[$opt.data.radiobutton],function(key,value){
    			var html = 	'<div class="" style="width:33%;display:inline-block">'+
    							'<label class="inline">'+
									'<input name="radioButton" type="radio" class="ace" value="'+value.name+'">'+
									'<span class="lbl middle">'+value.name+'-'+value.value+'</span>'+
								'</label>'+
    						'</div>';
    			el.find("#radioDiv").append(html);
    		})
		},
    	//绑定事件
    	bindEvent:function(){
    		var $t=this;
    		var $opt=$t.options;
    		var el=$t.$element;
    		
    		//确定
    		el.find("#btnDataBack").unbind("click").click(function(){
    			var value = $("#radioDiv input[name='radioButton']:checked").val()
    			$opt.dataBack(value)
    		})
    	},
    	
    	//模态显示
    	show:function(){
    		var $t=this;
    		var $opt=$t.options;
    		var el=$t.$element;
    		
    		$(el).modal({backdrop: 'static', keyboard: true},"show");
    	},
    }
})(jQuery);